{% extends "group/group_base.html" %}
{# Copyright The IETF Trust 2015-2020, All Rights Reserved #}
{% load origin %}
{% origin %}
{% load ietf_filters static django_bootstrap5 person_filters %}
{% block pagehead %}
    <link rel="stylesheet" href="{% static "ietf/css/list.css" %}">
{% endblock %}
{% block group_subtitle %}Reviewers{% endblock %}
{% block group_content %}
    {% origin %}
    {% if can_access_stats %}
        <div class="float-end">
            <a href="{% url "ietf.stats.views.review_stats" stats_type="completion" acronym=group.acronym %}"
               aria-label="Statistics"
               class="icon-link">
                <i class="bi bi-bar-chart-line"></i>
            </a>
        </div>
    {% endif %}
    <h2 class="mt-3">Reviewers</h2>
    <p>
        Status of the reviewers in {{ group.acronym }}, ordered by their
        rotation with the next reviewer in the rotation at the top. Rows with darker backgrounds have the following meaning:
    </p>
    <div class="reviewer-overview">
        <p class="alert alert-info my-3">
            Has already been assigned a document within the given interval.
        </p>
        <p class="alert alert-warning my-3">
            Will be skipped the next time at the top of rotation.
        </p>
        <p class="alert alert-danger my-3">
            Is not available to do reviews at this time.
        </p>
    </div>
    {% if can_reset_next_reviewer %}
        <div>
            <a href="{% url 'ietf.group.views.reset_next_reviewer' acronym=group.acronym %}"
               class="btn btn-primary"
               id="reset_next_reviewer">
                Reset head of queue
            </a>
        </div>
    {% endif %}
    {% if reviewers %}
        <table class="table table-sm table-striped reviewer-overview tablesorter">
            <thead>
                <tr>
                    <th scope="col" data-sort="next">Next</th>
                    <th scope="col" data-sort="reviewer">Reviewer</th>
                    <th scope="col">
                        <div class="row">
                            <div class="col-md-2 me-1">Assigned</div>
                            <div class="col-md-2 me-1 d-none d-lg-block">Deadline</div>
                            <div class="col-md-2 me-1">State</div>
                            <div class="col-md-1 me-1 d-none d-lg-block">Days for review</div>
                            <div class="col">Document</div>
                        </div>
                    </th>
                    <th scope="col" data-sort="num">Days since review</th>
                    <th scope="col" class="d-none d-xl-table-cell w-25">Settings</th>
                </tr>
            </thead>
            <tbody>
                {% for person in reviewers %}
                    <tr {% if person.completely_unavailable %}class="table-danger" title="Is not available to do reviews at this time." {% elif person.busy %}class="table-info" title="Has already been assigned a document within the given interval." {% elif person.settings.skip_next %}class="table-warning" title="Will be skipped the next time at the top of rotation." {% endif %}>
                        <td>{{ forloop.counter }}</td>

                        <td>
                            {% person_link person with_email=False %}

                            <div class="text-nowrap">
                                {% if person.settings_url %}
                                    <a href="{{ person.settings_url }}" class="btn btn-primary btn-sm"
                                        aria-label="Change settings for {{ person.name }}">
                                        <i class="bi bi-gear"></i>
                                    </a>
                                {% endif %}
                                <button type="button"
                                        class="btn btn-primary btn-sm d-xl-none"
                                        aria-label="View settings for {{ person.name }}"
                                        data-bs-toggle="modal"
                                        data-bs-target="#modal{{ forloop.counter }}">
                                  <i class="bi bi-search"></i>
                                </button>
                            </div>
                        </td>

                        <td>
                            {% if person.latest_reqs %}
                                {% for assn_pk, req_pk, doc_name, reviewed_rev, assigned_time, deadline, state, assignment_to_closure_days in person.latest_reqs %}
                                    <div class="row {% if not forloop.last %}border-bottom mb-1 pb-1{% endif %}">
                                        <div class="col-md-2 me-1">
                                            {{ assigned_time|date|split:"-"|join:"-<wbr>" }}
                                        </div>
                                        <div class="col-md-2 me-1 d-none d-lg-block">
                                            <a href="{% url 'ietf.doc.views_review.review_request' name=doc_name request_id=req_pk %}">{{ deadline|date|split:"-"|join:"-<wbr>" }}</a>
                                        </div>
                                        <div class="col-md-2 me-1">
                                            {{ state.name|badgeify }}
                                        </div>
                                        <div class="col-md-1 me-1 text-end d-none d-lg-block">
                                            {% if assignment_to_closure_days != None %}
                                                {{ assignment_to_closure_days }}
                                            {% endif %}
                                        </div>
                                        <div class="col">
                                            {{ doc_name }}{% if reviewed_rev %}-{{ reviewed_rev }}{% endif %}
                                        </div>
                                    </div>
                                {% endfor %}
                            {% endif %}
                        </td>

                        <td class="text-end">
                            {% if person.days_since_completed_review != 9999 %}
                                {{ person.days_since_completed_review }}
                            {% endif %}
                        </td>

                        <td class="d-none d-xl-table-cell w-25">
                            {% include "review/unavailable_table.html" with person=person unavailable_periods=person.unavailable_periods %}
                            <div class="modal modal-xl fade" id="modal{{ forloop.counter }}" tabindex="-1" aria-labelledby="modallabel{{ forloop.counter }}" aria-hidden="true">
                              <div class="modal-dialog">
                                <div class="modal-content">
                                  <div class="modal-header">
                                    <h1 class="modal-title fs-5" id="modallabel{{ forloop.counter }}">Reviewer settings</h1>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                  </div>
                                  <div class="modal-body">
                                    {% include "review/unavailable_table.html" with person=person unavailable_periods=person.unavailable_periods %}
                                  </div>
                                  <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                                    <button type="button" class="btn btn-primary">Save changes</button>
                                  </div>
                                </div>
                              </div>
                            </div>
                        </td>

                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>
            No reviewers found.
        </p>
    {% endif %}
{% endblock %}
{% block js %}
    <script src="{% static "ietf/js/list.js" %}"></script>
{% endblock %}